<!--
    作者：offline
	时间：2019-05-36
	描述：测试模板2
-->
<template>
    <div class="m-view-testModel m-window" id="testApp">
        <div class="m-condition">
            <el-row :gutter="10">
                <el-col :span="6">
                    <el-input placeholder="请输入公司编号/名称" clearable v-model="name"></el-input>
                </el-col>
            </el-row>
        </div>
        <div class="m-agTable m-bottom">
            <!-- <agGridComponent ref="agGridComponent" :getColumnDefs = "columnDefs" :tableName="tableName" :getGridOptions="gridOptions" :getRowData="rowData"></agGridComponent> -->
			<ag-grid-component ref="agGridComponent" :getColumnDefs = "columnDefs" :tableName="tableName" :getGridOptions="gridOptions" :getRowData="rowData"></ag-grid-component>
        </div>
    </div>
</template>

<script>
    // import agGridComponent from "lesso-common/public/agGridComponent.vue";
    import testData from "@/views/masterData/testData.js";
	import Vue from "vue";
	import _Api from "@/api";

	const operation = Vue.extend({
		template:`<span>
		<el-button @click="operation" class="rendererClass" size="mini">操作</el-button>
		</span>`,
		data(){
			return{
			}
		},
		methods:{
			operation(){
				this.params.context.componentParent.operation(this.params.node.data);
			}
		}
	})

    export default {
        data(){
            return{
                name:"",
                columnDefs:[],
                gridOptions:{},
				// tableName:"testModule2",
				tableName:'',
				rowData:[]
            }
        },
        components:{
            // agGridComponent
        },
        beforeMount(){
			this.gridOptions = {
				context:{
					componentParent: this
				}
			}
            this.columnDefs = [
				// {
				// 	headerName: "Country",
				// 	field: "country",
				// 	width: 120
				// },
				// {
				// 	headerName: "Year",
				// 	field: "year",
				// 	width: 90
				// },
				// {
				// 	headerName: "Date",
				// 	field: "date",
				// 	width: 110
				// },
				// {
				// 	headerName: "Sport",
				// 	field: "sport",
				// 	width: 110
				// },
				// {
				// 	headerName: "Gold",
				// 	field: "gold",
				// 	width: 100
				// },
				// {
				// 	headerName: "Silver",
				// 	field: "silver",
				// 	width: 100
				// },
				// {
				// 	headerName: "Bronze",
				// 	field: "bronze",
				// 	width: 100
				// },
				{	
					headerName:"公司编号",
					field:"companyCode"
				},
				{
					headerName:"Operation",
					field:"operation",
					width:120,
					cellRendererFramework:operation
				}
			];
			// this.rowData = testData;
			this.getRowData();
        },
        mounted(){
			this.$refs.agGridComponent.agGridOptions.api.forEachNode(function(node){
				if(node.data.athlete == 'Michael Phelps')
					node.setSelected(true);
			})
		},
		methods:{
			operation(params){
				this.$message({
					message:params,
					type:'success'
				});
			},
			getRowData(){
				var obj = {};
				var that = this;
				obj.state = 1;
				obj.current = 1;
				obj.size = 30;
				_Api.getCompanyInfo(obj).then((response) => {
					var data = response.data;
					if(data.code == 1){
						if(data.total > 0){
							// that.$refs.agGridComponent.agGridOptions.api.setRowData( data.rows.splice(0));
							that.rowData = data.rows.splice(0);
						}else{
							that.rowData = [];
						}
					}
				})
			}
		}
    }
</script>

